home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
varia
/
gc-nov90.lha
/
gc-26nov90
/
gcstring.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-11-01
|
913b
|
46 lines
/* A string class based on the one at pg 184 of "The C++ Programming Language"
that uses heap allocated storage.
*/
#include "gcstring.h"
void gc_string::GCPointers() {}
gc_string::gc_string( char* chars ) {
int len = strlen( chars );
GCALLOCV( gc_string, len+1+sizeof( int ) );
length = len;
strcpy( &text, chars );
}
gc_string::gc_string( int chars ) {
GCALLOCV( gc_string, chars+1+sizeof( int ) );
length = chars;
}
char& string::operator[]( int i ) {
if (i < 0 || i >= sp->length) {
cout << "String index out of bounds\n";
exit( 1 );
}
return *((&sp->text)+i);
}
istream& operator>>( istream& in, string& y ) {
char buf[ 1024 ];
in >> buf;
y.sp = new gc_string( buf );
return in;
}
string stringplus( char* x, int xl, char* y, int yl ) {
string xy;
xy.sp = new gc_string( xl+yl );
strcpy( &xy.sp->text, x );
strcpy( (&xy.sp->text)+xl, y );
return xy;
}